//
//  OrderDetailViewController.m
//  much
//
//  Created by Believer Just on 2019/1/11.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "ShoppingCartCell.h"
#import "OrderDetailBottomView.h"
#import "OrderDetailAddressTableViewCell.h"
#import "OrderLogisticsTableViewCell.h"
/**
#import "PaySelectViewController.h"
#import "NewStoreRefundViewController.h"
#import "NewStoreNewRefundViewController.h"
#import "NewStoreDetailViewController.h"
#import "BasicWebViewController.h"
#import "PayResultViewController.h"
#import "PayOrderRequestManager.h"
 */

@interface OrderDetailViewController () <UITableViewDelegate, UITableViewDataSource>

@property (assign, nonatomic) NSInteger ablePointCount;

@property (strong, nonatomic) UITableView * tableView;
@property (strong, nonatomic) UIView * tableFooterView;
@property (strong, nonatomic) NSMutableArray * otherInfotArray;//其他内容，包含订单支付信息，运单信息
@property (strong, nonatomic) OrderDetailBottomView * orderDetailBottomView;

@property (nonatomic, copy) MyOrderLogisticsTracksModel *logisticsModel; // 物流信息Model

@property (nonatomic, assign) BOOL isShowLogistics; // 是否显示物流信息

@end

@implementation OrderDetailViewController

- (void)_reLayout {
    self.title = @"订单详情";
    /**
    self.ablePointCount = USER.userBaseInfo.account.point;
     */
    
    [self updateOrderOtherInfo];
    [self.tableView reloadData];
    
    [self loadOrderDetailData];
}
/** 获取详情 */
- (void)loadOrderDetailData {
    /**
    [StoreRequestManager userGetOrderDetailWithOrderId:self.order.orderId sucess:^(Orders * data) {
        self.order = data;
        [self updateOrderOtherInfo];
        self.orderDetailBottomView.model = data;
        
        [self loadLogisticsHTTP:data.transportId];
        [self.tableView reloadData];
    } fail:^(NSString * error) {
        
    }];
     */
}
/** 获取物流 */
- (void)loadLogisticsHTTP:(NSString *)transportId {
    if (transportId.hasValue) {
        /**
        [StoreRequestManager userGetLogisticsWithId:transportId company:self.order.transportCompany sucess:^(MyOrderLogisticsModel *model) {
            if (model.tracks.count > 0) {
                self.logisticsModel = model.tracks[0];
                self.isShowLogistics = YES;
            } else {
                self.isShowLogistics = NO;
            }
            [self.tableView reloadData];
        } fail:^(NSString *error) {
            
        }];
         */
    }
}
/** 更新订单中的订单信息和运单信息 */
- (void)updateOrderOtherInfo {
    // 主要用于组装订单详情中展示的详情信息，只要调用该方法，都会重载数组中的数据
    self.otherInfotArray = [[NSMutableArray alloc] init];
    
    /**
    // 支付信息
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    NSDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"支付方式：" forKey:@"title"];
    [dict setValue:self.order.payChannelText forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"商品合计：" forKey:@"title"];
    [dict setValue:[NSString stringWithFormat:@"¥%@", self.order.amount] forKey:@"content"];
    [arr addObject:dict];
    
    if (self.order.benefit == JoinHuiyuanMallType) {
        dict = [[NSMutableDictionary alloc] init];
        [dict setValue:@"积分：" forKey:@"title"];
        [dict setValue:[NSString stringWithFormat:@"%@", @(self.order.pointCount)] forKey:@"content"];
        [arr addObject:dict];
    } else if (self.order.benefit == PartDeduction && self.order.pointCount > 0) {
        dict = [[NSMutableDictionary alloc] init];
        [dict setValue:@"积分：" forKey:@"title"];
        [dict setValue:[NSString stringWithFormat:@"%@", self.order.pointAmountText] forKey:@"content"];
        [arr addObject:dict];
    }
    
    // 判断优惠大于0 显示优惠金额
    if (self.order.discountAmount.hasValue && self.order.discountAmount.floatValue > 0) {
        dict = [[NSMutableDictionary alloc] init];
        [dict setValue:@"优惠：" forKey:@"title"];
        [dict setValue:[NSString stringWithFormat:@"¥%@", self.order.discountAmount] forKey:@"content"];
        [arr addObject:dict];
    }
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"运费：" forKey:@"title"];
    [dict setValue:[NSString stringWithFormat:@"¥%@", self.order.shippingFee] forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"发票抬头：" forKey:@"title"];
    [dict setValue:self.order.invoiceTitle forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"发票内容：" forKey:@"title"];
    [dict setValue:self.order.invoiceContent forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"交易时间：" forKey:@"title"];
    [dict setValue:self.order.paymentCreateTime forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"交易流水号：" forKey:@"title"];
    [dict setValue:self.order.paymentId forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"支付订单号：" forKey:@"title"];
    [dict setValue:self.order.sysOrderId forKey:@"content"];
    [arr addObject:dict];
    [self.otherInfotArray addObject:arr];
    
    // 运费信息
    arr = [[NSMutableArray alloc] init];
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"承运来源：" forKey:@"title"];
    [dict setValue:self.order.transportCompany forKey:@"content"];
    [arr addObject:dict];
    
    dict = [[NSMutableDictionary alloc] init];
    [dict setValue:@"运单编号：" forKey:@"title"];
    [dict setValue:self.order.transportId forKey:@"content"];
    [arr addObject:dict];
    [self.otherInfotArray addObject:arr];
     */
}
/** 积分订单支付 */
/**
- (void)pushPayResultControllerVCWithPayResultState:(PayResultState)state orderDataModel:(Orders *)orderDataModel {
    PayResultViewController *vc = [[PayResultViewController alloc] initWithPayResult:state payData:nil orderType:OrderTypeScoreOrder];
    vc.fromControllerResultType = FromControllerResultTypeOrderDetail;
    orderDataModel.ablePointCount = self.ablePointCount;
    vc.myselfScore = [NSString stringWithFormat:@"%@", @(orderDataModel.ablePointCount - orderDataModel.pointCount)];
    vc.orderUseScore = [NSString stringWithFormat:@"%@", @(orderDataModel.pointCount)];
    vc.payMentAgainBlock = ^(PayResultState result) {
        if (result == CurrencyExchangeResultsSuccess) {
            self.ablePointCount -= orderDataModel.pointCount;
            [self loadOrderDetailData];
            [self changeSuccessWithFooterViewBtnType:FooterViewBtnTypeSroceOrderSucces];
        }
    };
    BasicNavigationController * nav = [[BasicNavigationController alloc] initWithRootViewController:vc];
    [APP.rootNavigationController presentViewController:nav animated:YES completion:nil];
}
 */
/** 支付 */
- (void)payOrder:(Orders *)model {
    /**
    if (model.benefit == JoinHuiyuanMallType) {
        [PayOrderRequestManager loadOrderDataWithPaySelect:PaySelectTypeIntegral type:2 orderId:model.orderId sucess:^(id data) {
            [self pushPayResultControllerVCWithPayResultState:CurrencyExchangeResultsSuccess orderDataModel:model];
        } fail:^(NSString * error) {
            [self pushPayResultControllerVCWithPayResultState:CurrencyExchangeResultsFail orderDataModel:model];
        }];
    } else {
        PaySelectViewController * vc = [[PaySelectViewController alloc] init];
        vc.orderId = model.orderId;
        vc.payType = 2;
        vc.needPayMoney = model.realAmount;
        vc.orderTypeString = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }
     */
}
/** 确认收货 */
- (void)sureHavaReceiveGoodsWithOrder:(Orders *)model {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"您是否已收到该订单商品？" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"未收货" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:cancelAction];
    
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"已收货" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        /**
        [StoreRequestManager userSureHaveReceivedGoodsWithOrderId:model.orderId sucess:^(id data) {
            [self loadOrderDetailData];
            [self changeSuccessWithFooterViewBtnType:FooterViewBtnTypeHasReceived];
        } fail:^(NSString * error) {
            [SVProgressHUD showErrorWithStatus:error];
        }];
         */
    }];
    [alertController addAction:sureAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
/** 删除订单 */
- (void)deleteOrderWithOrder:(Orders *)model {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:@"确认删除此订单？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:cancelAction];
    
    UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        /**
        [StoreRequestManager userDeleteOrderWithOrderId:model.orderId sucess:^(id data) {
            [self loadOrderDetailData];
            [self changeSuccessWithFooterViewBtnType:FooterViewBtnTypeDeteleOrder];
        } fail:^(NSString * error) {
            [SVProgressHUD showErrorWithStatus:error];
        }];
         */
    }];
    [alertController addAction:sureAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
/** 取消订单 */
- (void)cancelOrderWithOrder:(Orders *)model {
    NewBaseAlertView *newBaseAlertView = [[NewBaseAlertView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) Message:@"" Distruction:@"我还在等着你，三思啊～" CancelButtonTitle:@"考虑一下" SureButtonTitle:@"坚决离开" ButtonNum:2 alertType:NewBaseAlertViewNormalType];
    __weakConfigure
    newBaseAlertView.newBaseAlertViewBlock = ^(NewBaseAlertViewButtonType type) {
        switch (type) {
            case NewBAVCancelBtnType:
                break;
            case NewBAVSureBtnType: {
                /**
                [StoreRequestManager userCancelOrderWithOrderId:model.orderId sucess:^(id data) {
                    [__weakSelf loadOrderDetailData];
                    [__weakSelf changeSuccessWithFooterViewBtnType:FooterViewBtnTypeCancelOrder];
                } fail:^(NSString *error) {
                    [SVProgressHUD showErrorWithStatus:error];
                }];
                 */
                break;
            }
            default:
                break;
        }
    };
    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:newBaseAlertView preferredStyle:TYAlertControllerStyleActionSheet];
    [self presentViewController:alertController animated:YES completion:nil];
}
/** 退换货按钮事件 */
/**
- (void)refundActionWithModel:(Orders *)model {
    NewStoreRefundViewController * vc = [[NewStoreRefundViewController alloc] init];
    vc.orderId = model.orderId;
    vc.type = 1;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)newRefundActionWithModel:(Orders *)model {
    NewStoreNewRefundViewController *vc = [[NewStoreNewRefundViewController alloc] init];
    vc.orderId = model.orderId;
    vc.type = 1;
    [self.navigationController pushViewController:vc animated:YES];
}
 */
/** 按钮操作成功后的回调 */
- (void)changeSuccessWithFooterViewBtnType:(FooterViewBtnType)footerViewBtnType {
    if (self.orderDetailChangeBlock) {
        self.orderDetailChangeBlock(footerViewBtnType, self.order);
    }
}


#pragma mark - <UITableViewDataSource, UITableViewDelegate>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.isShowLogistics) {
        return 3 + self.otherInfotArray.count;
    } else {
        return 2 + self.otherInfotArray.count;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.isShowLogistics) {
        if (section == 0) {
            return 1;
        } else if (section == 1) {
            return 1;
        } else if (section == 2) {
            return self.order.spus.count;
        } else {
            return [self.otherInfotArray[section - 3] count];
        }
    } else {
        if (section == 0) {
            return 1;
        } else if (section == 1) {
            return self.order.spus.count;
        } else {
            return [self.otherInfotArray[section - 2] count];
        }
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger section = indexPath.section;
    if (self.isShowLogistics) {
        if (section == 0) {
            OrderDetailAddressTableViewCell *cell = [OrderDetailAddressTableViewCell initTableView:tableView];
            return cell;
        } else if (section == 1) {
            OrderLogisticsTableViewCell *cell = [OrderLogisticsTableViewCell initTableView:tableView];
            return cell;
        } else if (section == 2) {
            NSString *identifier = @"MyOrderListCell";
            ShoppingCartCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (!cell) {
                cell = [[ShoppingCartCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier clickedViewTypeInShoppingCart:ClickedViewTypeInShoppingCartOrderCell];
            }
            return cell;
        } else {
            NSString *identifier = @"cell";
            BasicCell *cell = [BasicCell initTableView:tableView];
            
            cell.textLabel.font = APPFONT(13);
            cell.textLabel.textColor = Color140;
            cell.detailTextLabel.font = APPFONT(13);
            cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
            cell.detailTextLabel.textColor = Color80;
            
            return cell;
        }
    } else {
        if (section == 0) {
            NSString *identifier = @"addressCell";
            OrderDetailAddressTableViewCell *cell = [OrderDetailAddressTableViewCell initTableView:tableView];
            return cell;
        } else if (section == 1) {
            NSString *identifier = @"MyOrderListCell";
            ShoppingCartCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (!cell) {
                cell = [[ShoppingCartCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier clickedViewTypeInShoppingCart:ClickedViewTypeInShoppingCartOrderCell];
            }
            return cell;
        } else {
            BasicCell *cell = [BasicCell initTableView:tableView];
            cell.textLabel.font = APPFONT(13);
            cell.textLabel.textColor = Color140;
            cell.detailTextLabel.font = APPFONT(13);
            cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
            cell.detailTextLabel.textColor = Color80;
            
            return cell;
        }
    }
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(BasicCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.isShowLogistics) {
        if (indexPath.section == 0) {
            ((OrderDetailAddressTableViewCell *)cell).model = self.order;
        } else if (indexPath.section == 1) {
            ((OrderLogisticsTableViewCell *)cell).model = self.logisticsModel;
            /**
            [((OrderLogisticsTableViewCell *)cell) setArrowTitleHidden:![self.order.transportIds containsString:@","]];
             */
        } else if (indexPath.section == 2) {
            GoodsModel *goodsModel = [self.order.spus objectAtIndex:indexPath.row];
            /**
            goodsModel.groupBuying = self.order.groupBuying;
            goodsModel.sellingPrice = goodsModel.unitPrice;
             */
            [((ShoppingCartCell *)cell) setModel:goodsModel isOrderDetail:YES];
            ((ShoppingCartCell *)cell).editStatus = NO;
        } else {
            NSArray *arr = [self.otherInfotArray objectAtIndex:indexPath.section - 3];
            NSDictionary *dict = [arr objectAtIndex:indexPath.row];
            cell.textLabel.text = [dict valueForKey:@"title"];
            cell.detailTextLabel.text = [NSString backDefaultIfNilWithString:[dict valueForKey:@"content"] defaultString:@"-"];
        }
    } else {
        if (indexPath.section == 0) {
            ((OrderDetailAddressTableViewCell *)cell).model = self.order;
        } else if (indexPath.section == 1) {
            GoodsModel *goodsModel = [self.order.spus objectAtIndex:indexPath.row];
            /**
            goodsModel.sellingPrice = goodsModel.unitPrice;
            goodsModel.groupBuying = self.order.groupBuying;
             */
            [((ShoppingCartCell *)cell) setModel:goodsModel isOrderDetail:YES];
            ((ShoppingCartCell *)cell).editStatus = NO;
        } else {
            NSArray *arr = [self.otherInfotArray objectAtIndex:indexPath.section - 2];
            NSDictionary *dict = [arr objectAtIndex:indexPath.row];
            cell.textLabel.text = [dict valueForKey:@"title"];
            cell.detailTextLabel.text = [NSString backDefaultIfNilWithString:[dict valueForKey:@"content"] defaultString:@"-"];
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger section = indexPath.section;
    if (self.isShowLogistics) {
        if (indexPath.section == 0) {
            return 88;
        } else if (section == 1)  {
            return 55;
        } else if (section == 2) {
            return 122;
        }
    } else {
        if (indexPath.section == 0) {
            return 88;
        } else if (section == 1) {
            return 122;
        }
    }
    return 24;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    NSInteger firtSectionNum;
    NSInteger secondSectionNum;
    if (self.isShowLogistics) {
        firtSectionNum = 3;
        secondSectionNum = 4;
    } else {
        firtSectionNum = 2;
        secondSectionNum = 3;
    }
    if (section == firtSectionNum || section == secondSectionNum) {
        return 15;
    }
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView * view = [[UIView alloc] init];
    view.backgroundColor = Color244;
    
    if (self.isShowLogistics) {
        if (section == 3 || section == 4) {
            UIView * line = [UIView new];
            line.backgroundColor = [UIColor whiteColor];
            [view addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(view);
                make.right.equalTo(view);
                make.bottom.equalTo(view);
                make.height.equalTo(view).dividedBy(3);
            }];
        }
    } else {
        if (section == 2 || section == 3) {
            UIView * line = [UIView new];
            line.backgroundColor = [UIColor whiteColor];
            [view addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(view);
                make.right.equalTo(view);
                make.bottom.equalTo(view);
                make.height.equalTo(view).dividedBy(3);
            }];
        }
    }
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (self.isShowLogistics) {
        if (section == 4) {
            return 15;
        } else if (section == 3) {
            return 5;
        }
    } else {
        if (section == 3) {
            return 15;
        } else if (section == 2) {
            return 5;
        }
    }
    
    return 0.001;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = Color244;
    
    if (self.isShowLogistics) {
        if (section == 3) {
            view.backgroundColor = [UIColor whiteColor];
        } else if (section == 4) {
            UIView * line = [UIView new];
            line.backgroundColor = [UIColor whiteColor];
            [view addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(view);
                make.right.equalTo(view);
                make.top.equalTo(view);
                make.height.equalTo(view).dividedBy(3);
            }];
        }
    } else {
        if (section == 2) {
            view.backgroundColor = [UIColor whiteColor];
        } else if (section == 3) {
            UIView * line = [UIView new];
            line.backgroundColor = [UIColor whiteColor];
            [view addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(view);
                make.right.equalTo(view);
                make.top.equalTo(view);
                make.height.equalTo(view).dividedBy(3);
            }];
        }
    }
    return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.isShowLogistics) {
        if (indexPath.section == 1) {
            /**
            NSString *urlString = [[NSString stringWithFormat:@"%@?company=%@&transportId=%@", kLogisticsBasicURL, self.order.transportCompanys,self.order.transportIds] urlEncode];
            BasicWebViewController *vc = [[BasicWebViewController alloc] initWithURL:urlString title:@"物流查询"];
            [self.navigationController pushViewController:vc animated:YES];
             */
        } else if (indexPath.section == 2) {
            GoodsModel * goodsModel = [self.order.spus objectAtIndex:indexPath.row];
            [self pushGoodsDetailWithGoodsModel:goodsModel];
        }
    } else {
        if (indexPath.section == 1) {
            GoodsModel * goodsModel = [self.order.spus objectAtIndex:indexPath.row];
            [self pushGoodsDetailWithGoodsModel:goodsModel];
        }
    }
}
- (void)pushGoodsDetailWithGoodsModel:(GoodsModel *)model {
    /**
    NewStoreDetailViewController *newStoreDetailVC = [[NewStoreDetailViewController alloc] init];
    model.sid = model.spuSid;
    newStoreDetailVC.goodsModel = model;
    if (model.groupBuying) {
        newStoreDetailVC.isGroupPurshase = YES;
    }
    [self.navigationController pushViewController:newStoreDetailVC animated:YES];
     */
}


#pragma mark - 懒加载
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tableView.backgroundColor = HEXCOLOR(0xf4f4f4);
        _tableView.dataSource = self;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.delegate = self;
        _tableView.dataArray = [[NSMutableArray alloc] init];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.tableFooterView = self.tableFooterView;
        _tableView.contentInset = UIEdgeInsetsMake(0, 0, 10, 0);
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view);
            make.top.equalTo(self.view);
            make.bottom.equalTo(self.orderDetailBottomView.mas_top);
            make.right.equalTo(self.view);
        }];
    }
    return _tableView;
}
- (UIView *)tableFooterView {
    if (!_tableFooterView) {
        _tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
        _tableFooterView.backgroundColor = [UIColor whiteColor];
        
        UILabel *lab = [UILabel new];
        lab.textColor = Color175030;
        lab.font = ICONFONT(14);
        lab.textAlignment = NSTextAlignmentCenter;
        lab.text = @"\uE6ce  在线客服";
        [_tableFooterView addSubview:lab];
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.left.and.bottom.equalTo(_tableFooterView);
            make.width.mas_equalTo(_tableFooterView.mas_width).multipliedBy(0.5);
        }];
        [self changeLabelText:lab];
        [lab tapUpWithBlock:^(UIView *v) {
            v.userInteractionEnabled = NO;
            /**
            [MQChatVCObject initMQChatVCObject:self customizedId:USER.userBaseInfo.profile.userSid orderId:self.order.orderId];
            */
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                v.userInteractionEnabled = YES;
            });
        }];
        
        UIView *lineView = [UIView new];
        lineView.backgroundColor = Color217;
        [_tableFooterView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lab.mas_right);
            make.height.mas_equalTo(_tableFooterView.mas_height).multipliedBy(0.6);
            make.width.mas_equalTo(0.5);
            make.centerY.equalTo(_tableFooterView);
        }];
        
        UILabel *phoneLab = [UILabel new];
        phoneLab.textColor = Color175030;
        phoneLab.font = ICONFONT(14);
        phoneLab.textAlignment = NSTextAlignmentCenter;
        phoneLab.text = @"\uE6e0  电话客服";
        [_tableFooterView addSubview:phoneLab];
        [phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.right.and.bottom.equalTo(_tableFooterView);
            make.width.mas_equalTo(_tableFooterView.mas_width).multipliedBy(0.5);
        }];
        [self changeLabelText:phoneLab];
        [phoneLab tapUpWithBlock:^(UIView *v) {
            v.userInteractionEnabled = NO;
            /**
            [self makePhoneCall:self.order.customerServicePhone];
             */
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                v.userInteractionEnabled = YES;
            });
        }];
    }
    return _tableFooterView;
}
- (void)changeLabelText:(UILabel *)label {
    // 同label不同字体大小
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSRange range = [label.text rangeOfString:@" "];
    NSDictionary *rangMoneydic = @{NSForegroundColorAttributeName:Color175030, NSFontAttributeName:ICONFONT(16)};
    NSDictionary *rangAfterdic = @{NSForegroundColorAttributeName:Color175030, NSFontAttributeName:APPFONT(14)};
    [attrString addAttributes:rangMoneydic range:NSMakeRange(0, range.location)];
    [attrString addAttributes:rangAfterdic range:NSMakeRange(range.location, label.text.length - range.location)];
    [label setAttributedText:attrString];
}
- (OrderDetailBottomView *)orderDetailBottomView {
    if (!_orderDetailBottomView) {
        _orderDetailBottomView = [[OrderDetailBottomView alloc] init];
        _orderDetailBottomView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_orderDetailBottomView];
        [_orderDetailBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view);
            make.bottom.equalTo(self.view);
            make.right.equalTo(self.view);
            make.height.mas_equalTo(49);
        }];
        
        UIView *line = [UIView new];
        line.backgroundColor = Color217;
        [_orderDetailBottomView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_orderDetailBottomView);
            make.top.equalTo(_orderDetailBottomView);
            make.right.equalTo(_orderDetailBottomView);
            make.height.mas_equalTo(1);
        }];
        
        __weak typeof(self) WeakSelf = self;
        _orderDetailBottomView.orderDetailBottomViewBlock = ^(FooterViewBtnType footerViewBtnType) {
            switch (footerViewBtnType) {
                case FooterViewBtnTypePayOrder:
                    [WeakSelf payOrder:WeakSelf.order];
                    break;
                case FooterViewBtnTypeHasReceived:
                    [WeakSelf sureHavaReceiveGoodsWithOrder:WeakSelf.order];
                    break;
                case FooterViewBtnTypeCancelOrder:
                    [WeakSelf cancelOrderWithOrder:WeakSelf.order];
                    break;
                case FooterViewBtnTypeDeteleOrder:
                    [WeakSelf deleteOrderWithOrder:WeakSelf.order];
                    break;
                case FooterViewBtnTypeApplyRefund:
                    /**
                    [WeakSelf refundActionWithModel:WeakSelf.order];
                     */
                    break;
                default:
                    break;
            }
        };
    }
    return _orderDetailBottomView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setShadowImage:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
